package com.ostrich.cloud.ostrichGoodsService.infra.mapper;

import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.SecKillDto;
import com.ostrich.cloud.ostrichGoodsSercice.model.Dto.SecKillGoodDto;
import com.ostrich.cloud.ostrichGoodsService.infra.model.SecKill;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 秒杀表 Mapper 接口
 * </p>
 *
 * @author Lucas
 * @since 2022-10-31
 */
public interface SecKillMapper extends BaseMapper<SecKill> {


    @Select("<script>"+
            "SELECT * " +
            "from sec_kill" +
            "<where>" +
            "<if test='status != null and status.trim() != &quot;&quot;'>" +
            "and status = #{status}" +
            "</if>" +
            "</where>" +
            "</script>")
    @Results(id="gets",value = {
            @Result(property = "secId",column = "sec_id",id = true),
            @Result(property = "secKillGoodDto",column = "goods_id",one = @One(
                    select = "com.ostrich.cloud.ostrichGoodsService.infra.mapper.SecKillMapper.getGoodsById"
            ))
    })
    List<SecKillDto> getAllSecKillByStatus(String status);

    @Select("select * from goods where goods_id =#{goodId}")
    SecKillGoodDto getGoodsById(Integer goodId);


    @Select("select * from sec_kill where sec_id=#{secId}")
    @Results(id="ge",value = {
            @Result(property = "secId",column = "sec_id",id = true),
            @Result(property = "secKillGoodDto",column = "goods_id",one = @One(
                    select = "com.ostrich.cloud.ostrichGoodsService.infra.mapper.SecKillMapper.getGoodsById"
            ))
    })
    SecKillDto getSecKillResult(Integer secId);

}
